﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;
using System.Windows.Threading;

namespace ControlLibrary
{
    public class AutomatedStoryControl : StoryControl
    {
        void _timer_Tick(object sender, EventArgs e)
        {
            try
            {
                SelectedIndex = (this.SelectedIndex + 1) % (this.Items.Count);
                SelectedItem = this.Items[this.SelectedIndex];
            }
            catch (DivideByZeroException) { }
        }

        public static readonly DependencyProperty TimeDelayProperty = DependencyProperty.Register("TimeDelay", typeof(int), typeof(AutomatedStoryControl),new PropertyMetadata(3));
        public int TimeDelay
        {
            get { return (int)GetValue(TimeDelayProperty); }
            set { SetValue(TimeDelayProperty, value); }
        }

        DispatcherTimer _timer = new DispatcherTimer();
        public AutomatedStoryControl()
        {
            _timer.Interval = new TimeSpan(0, 0, 0, TimeDelay, 0);
            _timer.Tick+=new EventHandler(_timer_Tick);
            _timer.Start();
        }
    }
}
